package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.mapper.CheckItemMapper;
import com.itheima.health.mapper.PermissionMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.PermissionService;
import com.itheima.health.utils.resources.MessageConstant;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Service
@Transactional
public class permissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {


    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //  mp   配置插件：  完成分页 查询
        QueryWrapper queryWrapper = new QueryWrapper();//   封装查询条件
        queryWrapper.eq("is_delete", 0);
        Page<Permission> page = null;
        if (StringUtils.isEmpty(queryPageBean.getQueryString())) {
            page = page(new Page<Permission>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()), queryWrapper);
        } else {
            //   select  * from  xxxx where  name like  xxx  limit ?,?
            queryWrapper.like("name", queryPageBean.getQueryString());
            page = page(new Page<Permission>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()), queryWrapper);
        }
        PageResult result = new PageResult(page.getTotal(), page.getRecords());
        return result;
    }

    @Override
    public List<Permission> findAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_delete",0);
        List<Permission> list = list(queryWrapper);
        return list;
    }


}



